<template>
    <div>
        <Header></Header>
        <div>
            <group>
                <x-input title="新密码" label-width="80px" v-model="resetForm.userPwd" required   placeholder="请输入密码"></x-input>               
                <x-input title="重复密码" label-width="80px" v-model="resetForm.resPwd"  required placeholder="请再次输入密码"></x-input> 
            </group>
            <div style="padding:10px;"> 
                <x-button type="warn" @click.native="resetPwd">重置密码</x-button>
            </div>
        </div>
        <Footer></Footer>
    </div>
</template>

<script>
import Header from '@/components/commons/header/header'
import Footer from '@/components/commons/footer/footer'
import userController from '@/api/userController/index'
    export default {
      name:'resetPassword',
      data(){
          return {
              resetForm:{
                  userPwd:null,
                  code:null,
                  resPwd:null
              }
          }
      },
      created(){
        this.resetForm.code = this.$route.params.code;
      },
      components:{Header, Footer},
      methods:{
          resetPwd(){
              //验证form
            if(!this.resetForm.userPwd){
                 this.$vux.toast.show({
                    text: '请输入密码',
                    type:'warn'
                })
                return false
            }
            if(!this.resetForm.resPwd){
                 this.$vux.toast.show({
                    text: '请再次输入密码',
                    type:'warn'
                })
                return false
            }
            if(this.resetForm.resPwd!=this.resetForm.userPwd){
                 this.$vux.toast.show({
                    text: '两次输入的密码不一致',
                    type:'warn'
                })
                return false
            }
            var formData = {
                userPwd:this.resetForm.userPwd,
                code:this.resetForm.code,
            }
            userController.resetPwdByEmail(formData).then(response=>{
                if(response.success){
                    //修改成功跳转至登录页面
                    this.$router.push({name:'login' })
                    this.$vux.toast.show({
                    text: response.msg,
                    type:'success'
                })
                }else{
                     this.$vux.toast.show({
                    text: response.msg,
                    type:'warn'
                })
                }
            })

          }
      }
    }
</script>

<style scoped>

</style>